"""
Case Type   : 功能测试
Case Name   : 清理测试表和数据文件
Create At   : 2024-07-17
Owner       : qumin
Description :
        1.清理环境
Expect      :
        1.成功
History     :
"""
import os
import unittest

from yat.test import Node
from yat.test import macro

from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger




class CTest0004(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.pri_sh = CommonSH('primarydbuser')
        self.pri_node = Node('primarydbuser')
        self.constant = Constant()
        self.common = Common()
        self.target_path = os.path.join(macro.DB_BACKUP_PATH, "source_data")
        self.tab1 = 't_stringfunc_1'
        self.tab2 = 't_stringfunc_2'

    def test1(self):
        text = '-----step1:清理环境；expect:成功-----'
        self.log.info(text)
        sql = f"""drop table if exists {self.tab1} cascade;
            drop table if exists t{self.tab2} cascade;"""
        res = self.pri_sh.execut_db_sql(sql)
        self.log.info(res)
        del_cmd = f'rm -rf {self.target_path};'
        del_res = self.pri_node.sh(del_cmd).result()
        self.assertEqual(2, res.count(self.constant.DROP_TABLE_SUCCESS),
                         '执行失败' + text)
        self.assertIn('', del_res, '执行失败' + text)

    def tearDown(self):
        text = '-----清理环境完成-----'
        self.log.info(text)
        self.log.info(f'----{os.path.basename(__file__)} finish----')
